import 'package:acgn_pioneer/pages/reader/reader_page.dart';
import 'package:acgn_pioneer/pages/reader/reader_page_main.dart';
import 'package:acgn_pioneer/public.dart';
import 'package:acgn_pioneer/widgets/reader/models/_reader_state.dart';

mixin ReaderWidgetBase<T extends StatefulWidget> on State<T> {
  // 阅读器主体引用
  ReaderPageState readerPage;

  // 阅读器入口页引用
  ReaderPageMainState readerMainPage;

  /// 阅读器数据仓库引用
  ReaderState get readModel => readerPage.state;

  /// 用户信息
  UserModel user;

  UserRecordProvider userRecord;

  @override
  void initState() {
    super.initState();
    readerPage = ReaderPage.of(context);
    readerMainPage = ReaderPageMain.of(context);

    WidgetsBinding.instance.addPostFrameCallback((_) async {
      user = Provider.of<UserProvider>(context, listen: false).data;

      if (userRecord != null) {
        await userRecord.setUserRecord();
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
  }

  refreshView() {
    setState(() {});
  }
}
